package userTests;

import org.testng.annotations.Test;
import org.openqa.selenium.*;

public class WithdrawNewBankTests extends TestBaseUser {
    
    @Test
    public void testWithdraw() {
    	openMainPageUser();
		gotoSignInUser();
		LoginLogoutDataUser signIn = new LoginLogoutDataUser();
		signIn.phoneNumber = "955413233";
		signIn.password = "!23Qwe";
		fillSignInUser(signIn);
		submitSignInUser();
		
		pointCurrency();
        gotoWithdrawForm();
        gotoNewBankForm();
        fillNewBankForm();
        confirmNewBankData();
        
//       if (!wd.findElement(By.xpath("//form[@class='form-horizontal']/fieldset/div[1]/div/select//option[2]")).isSelected()) {
//            wd.findElement(By.xpath("//form[@class='form-horizontal']/fieldset/div[1]/div/select//option[2]")).click();
//        }
        
        wd.findElement(By.id("payment_details_id")).click();
        wd.findElement(By.id("someid")).click();
        wd.findElement(By.id("amount_integer")).click();
        wd.findElement(By.id("amount_integer")).clear();
        wd.findElement(By.id("amount_integer")).sendKeys("70");
        wd.findElement(By.id("comments")).click();
        wd.findElement(By.id("comments")).clear();
        wd.findElement(By.id("comments")).sendKeys("funds output");
        wd.findElement(By.name("preview")).click();
        wd.findElement(By.name("edit")).click();
        if (!wd.findElement(By.xpath("//form[@class='form-horizontal']/fieldset/div[1]/div/select//option[3]")).isSelected()) {
            wd.findElement(By.xpath("//form[@class='form-horizontal']/fieldset/div[1]/div/select//option[3]")).click();
        }
        wd.findElement(By.id("amount_integer")).click();
        wd.findElement(By.id("amount_integer")).clear();
        wd.findElement(By.id("amount_integer")).sendKeys("60");
        wd.findElement(By.id("comments")).click();
        wd.findElement(By.id("comments")).clear();
        wd.findElement(By.id("comments")).sendKeys("funds output edit");
        wd.findElement(By.name("preview")).click();
        wd.findElement(By.id("payment_password")).click();
        wd.findElement(By.id("payment_password")).clear();
        wd.findElement(By.id("payment_password")).sendKeys("1");
        wd.findElement(By.name("confirm")).click();
        wd.findElement(By.cssSelector("td.pointer")).click();
        wd.findElement(By.id("linkOperationDetails_704")).click();
        wd.findElement(By.cssSelector("button.btn.dialog-close-btn")).click();
        wd.findElement(By.linkText("Мои поручения")).click();
        wd.findElement(By.id("linkPaymentOrderDetails_188")).click();
        wd.findElement(By.cssSelector("button.btn.dialog-close-btn")).click();
        wd.findElement(By.linkText("Мои счета")).click();
        wd.findElement(By.linkText("Выйти")).click();
    }

	private void confirmNewBankData() {
		wd.findElement(By.cssSelector("button.btn.btn-primary")).click();
	}

	private void fillNewBankForm() {
		wd.findElement(By.id("name")).click();
        wd.findElement(By.id("name")).clear();
        wd.findElement(By.id("name")).sendKeys("Euro-bank");
        wd.findElement(By.id("iban")).click();
        wd.findElement(By.id("iban")).clear();
        wd.findElement(By.id("iban")).sendKeys("12345678901");
        wd.findElement(By.id("real_name")).click();
        wd.findElement(By.id("real_name")).clear();
        wd.findElement(By.id("real_name")).sendKeys("Komoleva");
        wd.findElement(By.id("real_name")).click();
        wd.findElement(By.id("real_name")).clear();
        wd.findElement(By.id("real_name")).sendKeys("Komoleva");
        wd.findElement(By.id("address")).click();
        wd.findElement(By.id("address")).clear();
        wd.findElement(By.id("address")).sendKeys("Kiev");
        wd.findElement(By.id("swift")).click();
        wd.findElement(By.id("swift")).clear();
        wd.findElement(By.id("swift")).sendKeys("98765432101");
        wd.findElement(By.id("bank_name")).click();
        wd.findElement(By.id("bank_name")).clear();
        wd.findElement(By.id("bank_name")).sendKeys("Euro-bank");
	}

	private void gotoNewBankForm() {
		wd.findElement(By.xpath("//*[@id='contentArea']//div/p[2]/a")).click();
	}

	private void gotoWithdrawForm() {
		wd.findElement(By.id("btnWithdraw")).click();
	}
    
}
